package com.liu.mybatis.service.impl;

import com.liu.mybatis.domain.Employee;
import com.liu.mybatis.mapper.EmployeeMapper;
import com.liu.mybatis.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * 事务应该在service层
 */
@Service
/**
 * readOnly:是否只读
 * propagation ：事务传播机制
 *   Propagation.REQUIRED：(默认)支持当前事务,如果当前没有事务,则新建一个事务
 *   Propagation.REQUIRES_NEW：一定会新建一个事务
 *   Propagation.NEVER ：绝不出现事务
 *   Propagation.SUPPORTS : 支持
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private EmployeeMapper mapper;

    @Override
    public List<Employee> findAll() {
        return mapper.findAll();
    }


    @Override
    @Transactional
    public void save(Employee employee) {
        mapper.save(employee);
        //int i = 1/0;
    }
}
